package com.vcredit.creditcat.framework.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * MD5加密等
 * 
 *
 */
public class MD5Encoder {
	public final static SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMdd");
	
	public static String encode(String input) {
		StringBuilder sb = new StringBuilder();
		
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(input.getBytes());
			byte bb[] = md.digest();
			int i;
		
			for (byte b : bb) {
				i = b;		
				if (i < 0) i += 256;
				if (i < 16) sb.append("0");
				sb.append(Integer.toHexString(i));
			}
		} catch (NoSuchAlgorithmException e) {}
		
		return sb.toString();
	} 
	
	public static String generateToken(String url, String privateKey) {
		return encode(privateKey + SDF.format(new Date()) + url);
	}
}
